const app=getApp();
var moodStorage = {

  //插入数据
  //Record:数据记录
  addMoodRecordAsync:function(Record,callback,failCallback){
    app.globalData.DataBase.collection('MoodRecord').add({
      data:Record,
      success:function(result){
        callback();
      },
      fail:function(result){
        failCallback();
      }
    })
  },

  //按月读取
  //month:月份 string '05','12'
  getMonthRecordAsync:function(month,callback,failCallback){
    app.globalData.DataBase.collection('MoodRecord').where({
      _openid:app.globalData._openid,
      month:month,
    }).get({
      success:function(result){
        callback(result.data);
      },
      fail:function(result){
        failCallback();
      }
    })
  },

  //动态加载获取数据
  getDataRocordAsync:function(where,skip,take,callback){
    app.globalData.DataBase.collection('MoodRecord').where(where).skip(skip).limit(take).get({
      success:function(result){
        callback(result.data);
      },
      fail:function(result){
        console.log("FAIL!");
        failCallback();
      }
    })
  }
}
module.exports = moodStorage;//数据存取服务
